const app = getApp();
const common = require('../../utils/common.js');
const api = require('../../config/api.js');
var WxParse = require('../../lib/wxParse/wxParse');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    actInfo: {},

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      options
    })
    this.getActDet(options.id)
  },
  // 获取活动详情
  getActDet: function (id) {
    let that = this;
    common.request(api.actDet, {
      actId: id
    }, 'post').then(function (data) {
      if (data.type === 'success') {
        that.setData({
          actInfo: data.data
        });
        WxParse.wxParse('article', 'html', data.data.content, that, 5)
      }
    });
  },
  //活动报名
  actJoin() {
    
    let that = this;
    let giveBalance = that.data.actInfo.giveBalance || '1'
    let actWay = that.data.actInfo.actWay
    if (that.data.actInfo.actWay == 1) {
      wx.showModal({
        title: '友情提示',
        content: `此次活动需支付${giveBalance}瓯客券参加`,
        success: function (res) {
          if (res.confirm) {
            wx.navigateTo({
              url: '/pages/playGame/baoming/index?id=' + that.data.options.id +'&bi=' + giveBalance + '&type=' + actWay + '&Mid=' + that.data.options.query,
            })
          } else {
            console.log('用户点击取消')
          }
        }
      })
    }else{
      wx.navigateTo({
        url: '/pages/playGame/baoming/index?id=' + that.data.options.id +'&bi=' + giveBalance + '&type=' + actWay + '&Mid=' + that.data.options.query,
      })
    }
    // common.request(api.actJoin, {
    //   actId: that.data.options.id
    // }, 'post').then(function (data) {
    //   if (data.type === 'success') {
    //     common.showSuccessToast("报名成功");
    //     setTimeout(function () {
    //       wx.navigateBack({
    //         delta: 0
    //       })
    //     }, 1500);

    //   }
    // });
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '活动分享',
      path: '/pages/GameDet/index?id=' + this.data.options.id,
      query:this.data.actInfo.shareId,
      imageUrl: this.data.actInfo.imgUrl
    }
  },

  onShareTimeline(res) {
    return {
      title: '活动分享',
      path: '/pages/GameDet/index?id=' + this.data.options.id,
      imageUrl: this.data.actInfo.imgUrl
    }
  },

})